package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.manager.vo.brand.BrandDetailRespVo;
import com.atguigu.spzx.manager.vo.brand.BrandQueryRespVo;
import com.atguigu.spzx.manager.vo.brand.BrandSaveReqVo;
import com.atguigu.spzx.manager.vo.brand.BrandUpdateReqVo;
import com.atguigu.spzx.manager.entity.Brand;
import com.atguigu.spzx.common.result.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * BrandController
 * </p>
 *
 * @author flyduck
 * @since 2023/10/29
 */
@Api(tags = "品牌管理接口")
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @ApiOperation("查询所有品牌")
    @GetMapping("/getBrandList")
    public Result<List<BrandQueryRespVo>> getBrandList(){
        List<BrandQueryRespVo> respVoList = brandService.getBrandList();
        return Result.ok(respVoList);
    }

    @ApiOperation("分页查询")
    @GetMapping("/getBrandPage/{page}/{limit}")
    public Result<Page<BrandQueryRespVo>> getBrandPage(@PathVariable Integer page,
                              @PathVariable Integer limit){
        Page<Brand> pageParam = new Page<>(page, limit);
        Page<BrandQueryRespVo> pageModel = brandService.getBrandPage(pageParam);
        return Result.ok(pageModel);
    }

    @ApiOperation("添加")
    @PostMapping("/saveBrand")
    public Result<Void> saveBrand(@RequestBody BrandSaveReqVo reqVo){
        brandService.saveBrand(reqVo);
        return Result.ok();
    }


    @ApiOperation("修改")
    @PostMapping("/updateBrandById")
    public Result<Void> updateBrandById(@RequestBody BrandUpdateReqVo reqVo){
        brandService.updateBrandById(reqVo);
        return Result.ok();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/getBrandById/{id}")
    public Result<BrandDetailRespVo> getBrandById(@PathVariable Long id){
        BrandDetailRespVo respVo = brandService.getBrandById(id);
        return Result.ok(respVo);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/deleteBrandById/{id}")
    public Result<Void> deleteBrandById(@PathVariable Long id){
        brandService.deleteBrandById(id);
        return Result.ok();
    }
}
